<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <!--如果是IE 就以标准渲染-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

    <!-- 视窗——————响应式布局 -->
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />

    <!--当前页面的三要素-->
    <title>运维系统-深中二公局PCS设备</title>
    <meta name="description" content="聚能优电" />
    <meta http-equiv="keywords" content="聚能优电" />
    <script type="text/javascript" src="../js/verify.js"></script>
    <!-- css -->
    <link rel="stylesheet" type="text/css" href="../css/common/common.css" />
    <link rel="stylesheet" type="text/css" href="../css/mainmonitor_szcyj.css" />
</head>

<body>
    <div id="container" class="szcyj">
        <div class="szcyj_01">
            <!--主屏内容-->
            <div class="szcyj_screen">
                <div class="m_title">
                    <a href="JavaScript:history.go(-1);" class="back">
                        <img src="../images/back.svg" alt="" />
                    </a>
                    <span class="tit">PCS</span>
                </div>
                <div class="m_content">
                    <div class="sb_tit">
                        <span>设备名称:</span>
                        <select id="select" value="" class="arrowdown">
                            <!-- <option value=""></option>
                            <option value="0">北京</option>
                            <option value="1">上海</option>
                            <option value="2">广州</option>
                            <option value="3">深圳</option>
                            <option value="4">杭州</option> -->
                        </select>
                    </div>
                    <div class="zcscs cslist">
                        <div class="zcscs_tit list_tit">
                            <!-- <span class="tit_icon"></span> -->
                            <span class="tit_con">总参数</span>
                        </div>
                        <ul class="list_con" id="zcscs_con"></ul>
                    </div>
                    <div class="sbztcs cslist">
                        <div class="sbztcs_tit list_tit">
                            <!-- <span class="tit_icon"></span> -->
                            <span class="tit_con">设备状态</span>
                        </div>
                        <ul class="list_con" id="sbztcs_con"></ul>
                    </div>

                    <div class="jlxxcs cslist">
                        <div class="jlxxcs_tit list_tit">
                            <!-- <span class="tit_icon"></span> -->
                            <span class="tit_con">交流信息</span>
                        </div>
                        <ul class="list_con" id="jlxxcs_con"></ul>
                    </div>

                    <div class="zlxxcs cslist">
                        <div class="zlxxcs_tit list_tit">
                            <!-- <span class="tit_icon"></span> -->
                            <span class="tit_con">直流信息</span>
                        </div>
                        <ul class="list_con" id="zlxxcs_con"></ul>
                    </div>

                    <div class="wdcs cslist">
                        <div class="wdcs_tit list_tit">
                            <!-- <span class="tit_icon"></span> -->
                            <span class="tit_con">温度</span>
                        </div>
                        <ul class="list_con" id="wdcs_con"></ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        (function (win, doc) {
            var docEl = doc.documentElement || document.body; //获取HTML标签

            var container = doc.getElementById("container"); //container元素
            //判断是移动端设备还是PC,移动 就采用'orientationchange',横竖屏事件，PC端就采用onresize，窗口改变时间
            var resize =
                "onorientationchange" in win ? "orientationchange" : "resize";

            function rem() {
                docEl.style.fontSize = 100 * (container.clientWidth / 750) + "px";
            }

            //监听'DOMContent事件:DOM加载完成执行,如果DOMContent事件，那么执行rem函数
            doc.addEventListener("DOMContentLoaded", rem, false);

            //win下监听resize事件,如果resize事件，那么执行rem函数
            win.addEventListener(resize, rem, false);
        })(window, document);
    </script>
    <!-- js -->
    <script type="text/javascript" src="../js/jquery-3.4.1.js"></script>
    <script>
        $(document).ready(function () {

            $.ajax({
                type: "GET",
                dataType: "json",
                url: "http://112.74.169.99:21021/api/services/app/DeviceService/GetADeviceInfoListByProjectId?id=3&typeid=1",
                beforeSend: function (xhr) {
                    xhr.setRequestHeader(
                        "Accept",
                        "application/json, text/javascript, */*; q=0.01"
                    );
                    xhr.setRequestHeader("Authorization", accessToken);
                    xhr.setRequestHeader(".AspNetCore.Culture", "zh-Hans");
                },
                success: function (res) {
                    var onoff = 0;
                    var defaulttimer;
                    var changetimer;
                    // console.log("PCS数据 请求成功");
                    var data = res.result;
                    if (data.length === 0) {
                        $(".m_content").html("暂无数据").css({
                            "font-size": "0.5rem",
                            "text-align": "center",
                            "color": "#fff",
                            "margin-top": "2.5rem"
                        });
                    } else {

                        $("#select").html(eachoption(data));
                        if (onoff == 0) {
                            var optionsdefaultid = $("#select option:selected").attr("valueid");
                            updateData(); // 首次加载立即请求数据
                            defaulttimer = setInterval(updateData, 1000); // 首次加载之后，每1s重新请求一次数据
                            function updateData() {
                                $.ajax({
                                    type: "GET",
                                    dataType: "json",
                                    url: "http://112.74.169.99:21021/api/services/app/ControlDataService/GetNewPCS_HistoryDataByID?Id=" +
                                        optionsdefaultid,
                                    beforeSend: function (xhr) {
                                        xhr.setRequestHeader(
                                            "Accept",
                                            "application/json, text/javascript, */*; q=0.01"
                                        );
                                        xhr.setRequestHeader("Authorization",
                                            accessToken);
                                        xhr.setRequestHeader(".AspNetCore.Culture",
                                            "zh-Hans");
                                    },
                                    success: function (res) {
                                        console.log("首次加载设备数据 请求成功");
                                        $("#zcscs_con").html("");
                                        $("#zcscs_con").html(eachzcscs(res));
                                        $("#sbztcs_con").html("");
                                        $("#sbztcs_con").html(eachsbztcs(res));
                                        $("#jlxxcs_con").html("");
                                        $("#jlxxcs_con").html(eachjlxxcs(res));
                                        $("#zlxxcs_con").html("");
                                        $("#zlxxcs_con").html(eachzlxxcs(res));
                                        $("#wdcs_con").html("");
                                        $("#wdcs_con").html(eachwdcs(res));
                                    },
                                    error: function (res) {
                                        console.log("首次加载设备数据 请求失败");
                                    }
                                });
                            }
                        }

                        // 切换下拉框操作
                        $("#select").change(function () {
                            onoff = 1;
                            clearInterval(defaulttimer);
                            clearInterval(changetimer);
                            var optionschangeid = $("#select option:selected").attr(
                                "valueid"
                            );
                            updateChangeData(); // 首次加载立即请求数据
                            changetimer = setInterval(updateChangeData,
                                1000); // 首次加载之后，每1s重新请求一次数据
                            function updateChangeData() {
                                $.ajax({
                                    type: "GET",
                                    dataType: "json",
                                    url: "http://112.74.169.99:21021/api/services/app/ControlDataService/GetNewPCS_HistoryDataByID?Id=" +
                                        optionschangeid,
                                    beforeSend: function (xhr) {
                                        xhr.setRequestHeader(
                                            "Accept",
                                            "application/json, text/javascript, */*; q=0.01"
                                        );
                                        xhr.setRequestHeader("Authorization",
                                            accessToken);
                                        xhr.setRequestHeader(
                                            ".AspNetCore.Culture",
                                            "zh-Hans");
                                    },
                                    success: function (res) {
                                        console.log("res", res)
                                        // console.log("切换设备数据 请求成功");
                                        $("#zcscs_con").html("");
                                        $("#zcscs_con").html(eachzcscs(res));
                                        $("#sbztcs_con").html("");
                                        $("#sbztcs_con").html(eachsbztcs(res));
                                        $("#jlxxcs_con").html("");
                                        $("#jlxxcs_con").html(eachjlxxcs(res));
                                        $("#zlxxcs_con").html("");
                                        $("#zlxxcs_con").html(eachzlxxcs(res));
                                        $("#wdcs_con").html("");
                                        $("#wdcs_con").html(eachwdcs(res));
                                    },
                                    error: function (res) {
                                        console.log("切换设备数据 请求失败");
                                    }
                                });
                            }
                        });
                    }
                },
                error: function (res) {
                    console.log("PCS数据 请求失败");
                }
            });


            function eachoption(obj) {
                var str = "";
                if (obj.constructor == Array) {
                    for (var i = 0, len = obj.length; i < len; i++) {
                        var option_value = obj[i].devCN;
                        var option_valueid = obj[i].id;
                        str +=
                            `<option value="` +
                            option_value +
                            `" valueid="` +
                            option_valueid +
                            `">` +
                            option_value +
                            `
                        </option>`;
                    }
                    return str;
                }
            }

            // 总参数
            function eachzcscs(obj) {
                var str = "";
                str +=
                    `<li><span class="con_left">总有功功率(kW)</span><span class="con_right">` +
                    obj.result.tap +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">总无功功率(kW)</span><span class="con_right">` +
                    obj.result.trp +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">总视在功率(kW)</span><span class="con_right">` +
                    obj.result.tApparentP +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">总功率因数</span><span class="con_right">` +
                    obj.result.tpf +
                    `</span></li>`;

                return str;
            }

            // 设备状态
            function eachsbztcs(obj) {
                obj.result.runState = 0 ? '关闭' : '运行'; // 运行状态
                obj.result.remoteControl = 0 ? '手动' : '自动'; // 控制模式
                if (obj.result.gridState == 0) {
                    // 并离网
                    obj.result.gridState = '并网';
                } else {
                    obj.result.gridState = '离网';
                }
                if (obj.result.warnState == 0) {
                    // 告警状态
                    obj.result.warnState = '无告警';
                } else {
                    obj.result.warnState = '有告警';
                }
                var str = "";
                str +=
                    `<li><span class="con_left">运行状态</span><span class="con_right">` +
                    obj.result.runState +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">控制模式</span><span class="con_right">` +
                    obj.result.remoteControl +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">并离网</span><span class="con_right">` +
                    obj.result.gridState +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">告警状态</span><span class="con_right">` +
                    obj.result.warnState +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">交流空开</span><span class="con_right">` +
                    obj.result.acEmpty +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">直流空开</span><span class="con_right">` +
                    obj.result.dcEmpty +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">交流调度</span><span class="con_right">` +
                    obj.result.acDispatch +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">直流调度</span><span class="con_right">` +
                    obj.result.dcDispatch +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">直流充电</span><span class="con_right">` +
                    obj.result.dcCharging +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">直流放电</span><span class="con_right">` +
                    obj.result.dcDischarge +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">直流充满</span><span class="con_right">` +
                    obj.result.dcFull +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">直流放空</span><span class="con_right">` +
                    obj.result.dcEmpting +
                    `</span></li>`;
                return str;
            }

            // 交流信息
            function eachjlxxcs(obj) {
                var str = "";
                str +=
                    `<li><span class="con_left">AB交流线电压(V)</span><span class="con_right">` +
                    obj.result.abacv +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">BC交流线电压(V)</span><span class="con_right">` +
                    obj.result.bcacv +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">CA交流线电压(V)</span><span class="con_right">` +
                    obj.result.caacv +
                    `</span></li>`;

                str +=
                    `<li><span class="con_left">A相交流电流(A)</span><span class="con_right">` +
                    obj.result.aaci +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">B相交流电流(A)</span><span class="con_right">` +
                    obj.result.baci +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">C相交流电流(A)</span><span class="con_right">` +
                    obj.result.caci +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">A相有功功率(kW)</span><span class="con_right">` +
                    obj.result.aap +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">B相有功功率(kW)</span><span class="con_right">` +
                    obj.result.bap +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">C相有功功率(kW)</span><span class="con_right">` +
                    obj.result.cap +
                    `</span></li>`;

                str +=
                    `<li><span class="con_left">A相无功功率(kW)</span><span class="con_right">` +
                    obj.result.arp +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">B相无功功率(kW)</span><span class="con_right">` +
                    obj.result.brp +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">C相无功功率(kW)</span><span class="con_right">` +
                    obj.result.crp +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">A相功率因数</span><span class="con_right">` +
                    obj.result.apf +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">B相功率因数</span><span class="con_right">` +
                    obj.result.bpf +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">C相功率因数</span><span class="con_right">` +
                    obj.result.cpf +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">A相视在功率(kW)</span><span class="con_right">` +
                    obj.result.aApparentP +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">B相视在功率(kW)</span><span class="con_right">` +
                    obj.result.bApparentP +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">C相视在功率(kW)</span><span class="con_right">` +
                    obj.result.cApparentP +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">交流有功充电电量(kWh)</span><span class="con_right">` +
                    obj.result.acacv +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">交流有功放电电量(kWh)</span><span class="con_right">` +
                    obj.result.acadv +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">交流频率(Hz)</span><span class="con_right">` +
                    obj.result.acFrequency +
                    `</span></li>`;
                return str;
            }

            // 直流信息
            function eachzlxxcs(obj) {
                var str = "";
                str +=
                    `<li><span class="con_left">直流功率(kW)</span><span class="con_right">` +
                    obj.result.dcp +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">直流电压(V)</span><span class="con_right">` +
                    obj.result.dcv +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">直流电流(A)</span><span class="con_right">` +
                    obj.result.dci +
                    `</span></li>`;
                return str;
            }

            // 温度
            function eachwdcs(obj) {
                var str = "";
                str +=
                    `<li><span class="con_left">散热器温度(℃)</span><span class="con_right">` +
                    obj.result.radiatorT +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">机柜温度(℃)</span><span class="con_right">` +
                    obj.result.cabinetT +
                    `</span></li>`;
                str +=
                    `<li><span class="con_left">环境温度(℃)</span><span class="con_right">` +
                    obj.result.environmentalT +
                    `</span></li>`;
                return str;
            }
        });
    </script>
</body>

</html>